package zjc.bookkeeping.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import zjc.bookkeeping.R;
import zjc.bookkeeping.db.ConsumptionClassBean;
import zjc.bookkeeping.tools.ToolsClass;

public class ConsumptionClassAdapter extends BaseAdapter {
    Context context;
    List<ConsumptionClassBean> consumptionClassBeanList;
    public int selectPos = 0;

    public ConsumptionClassAdapter(Context context, List<ConsumptionClassBean> consumptionClassBeanList) {
        this.context = context;
        this.consumptionClassBeanList = consumptionClassBeanList;
    }

    @Override
    public int getCount() {
        return consumptionClassBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return consumptionClassBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(context).inflate(R.layout.consumption_class_gv,viewGroup,false);
        ImageView imageView = view.findViewById(R.id.consumption_class_iv);
        TextView textView = view.findViewById(R.id.consumption_class_tv);
        ConsumptionClassBean consumptionClassBean = consumptionClassBeanList.get(i);
        textView.setText(consumptionClassBean.getConsumption_class_name());
        imageView.setImageResource(ToolsClass.getResourceId(consumptionClassBean.getConsumption_class_image()));
        if (selectPos == i){
            view.setBackgroundColor(context.getResources().getColor(R.color.blue_F0F9FC));
        }
        return view;
    }
}
